import json
import pytest
import requests
from jsonpath import jsonpath

from 接口测试.tools.read_Excel import read_data
from 接口测试.tools.read_pathlib import exc_path
from 接口测试.tools.handle_assert import handle_assert

search_cartcase = read_data(exc_path=exc_path,sheetname="搜索")


@pytest.mark.parametrize("data",search_cartcase)
def test02_search_cart(data):
    search_url = data["接口地址"]
    search_param = {"prodName":"小黄人来咯"}
    search_res = requests.request(method="get",url=search_url,params=search_param)
    handle_assert(search_res,data["预期结果"])
    prod_id = jsonpath(search_res.json(),"$..prodId")
    return prod_id